package cn;

import cn.dao.FlexMapper;
import cn.dao.OrdersMapper;
import cn.entity.Orders;
import cn.mapper.UserMapper;
import cn.entity.User;
import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.table.DynamicTableProcessor;
import com.mybatisflex.core.table.TableManager;
import com.mybatisflex.core.update.UpdateWrapper;
import com.ymx.darling.datasource.defaults.PooledDataSource;
import com.ymx.darling.session.Session;
import com.ymx.darling.session.SessionFactory;
import com.ymx.darling.session.SessionFactoryBuilder;
import org.apache.ibatis.logging.stdout.StdOutImpl;

public class DarlingTest {
    public static void main(String[] args) {
        PooledDataSource dataSource = new PooledDataSource();
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        dataSource.setDriver("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/darling");

//        TableManager.setDynamicTableProcessor(new DynamicTableProcessor() {
//            @Override
//            public String process(String tableName) {
//                return tableName + "_01";
//            }
//        });

        MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
                .addMapper(FlexMapper.class)
                .addMapper(OrdersMapper.class)
                .setLogImpl(StdOutImpl.class)
                .setDataSource(dataSource)
                .start();


        FlexMapper mapper = bootstrap.getMapper(FlexMapper.class);
        QueryWrapper queryWrapper = new QueryWrapper();

        queryWrapper.select("user.id", "user.age")
                .select(User::getPolitical)
                .from(User.class) //
                .join(Orders.class).on(User::getId, Orders::getUserId)
                .eq(User::getPolitical, "团员");
        mapper.selectListByQuery(queryWrapper);
    }
}
